let handler = require("../data_model_service_handler")
let ddl_handler = require("./ddl_handler")
let db = require("../../db/db")

handler.set_db(db);
ddl_handler.set_db(db);

let add = async function (data, login_info, req, res) {
    let rst = await handler.add(data, login_info, req, res);
    await ddl_handler.add_functions(rst.results.insertId, data.rows[0].page_type_id, login_info, req, res);
    return rst;
}
let del = async function (data, login_info, req, res) {
    let rst = await handler.del(data, login_info, req, res);
    let page_id = data.id;
    await ddl_handler.del_functions(page_id, login_info, req, res);
    //同时删掉菜单
    await db.update("update sys_menu set is_deleted=1,update_user=? where page_id=?", [login_info.user_id, page_id]);
    return rst;
}

module.exports = { add, del }